<template>
    <div class="container">
        <!-- 用户信息 -->
        <div class="user">
            <van-image class="img" width="100" height="100" :src="userInfo.avatar" alt="" />
            <div class="text">{{ userInfo.name }}</div>
        </div>
        <!-- 我的订单 -->
        <div class="order">
            <!-- 订单标题 -->
            <div class="top">
                <div class="text1">我的订单</div>
                <div class="text2">全部</div>
            </div>
            <!-- 订单状态 -->
            <div class="buttom">
                <div v-for="item in states" class="item" @click="goOrder(item.state)">
                    <van-image width="40" height="40" :src="item.src" />
                    <div>{{ item.text }}</div>
                </div>
            </div>
        </div>
        <!-- 底部功能 -->
        <div class="foot">
            <div class="foot1">
                <van-image style="width: 20px; height: 20px; margin: 10px 0;" src="/images/ic_clients.png" />
                <van-cell title="服务对象管理" is-link />
            </div>
            <div class="foot2">
                <van-image style="width: 20px; height: 20px; margin: 10px 0;" src="/images/ic_share.png" />
                <van-cell title="分享转发" is-link />
            </div>
        </div>

        <!-- 退出登录 -->
        <van-button class="quit" type="danger" size="large" @click="showQuit = true">退出登录</van-button>

        <!-- 退出登录弹窗 -->
        <van-dialog v-model:show="showQuit" title="提示" @confirm="quit" @cancel="showQuit = false" show-cancel-button>
            <div class="quit_text">是否确认退出登录？</div>
        </van-dialog>

    </div>
</template>

<script setup name="user">
import { ref, reactive, computed } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()

// 用户信息
const userInfo = computed(() => { return JSON.parse(localStorage.getItem('h5_userInfo')) || {} })

// 订单状态
const states = reactive([
    { state: 1, text: '待支付', src: '/images/od_10.png' },
    { state: 2, text: '待服务', src: '/images/od_20.png' },
    { state: 3, text: '已完成', src: '/images/od_30.png' },
    { state: 4, text: '已取消', src: '/images/od_40.png' }
])
// 跳转订单页面
const goOrder = (active) => {
    router.push(`/order?active=${active}`)
}

// 退出登录弹窗
const showQuit = ref(false)
// 确认退出登录
const quit = () => {
    showQuit.value = false
    localStorage.removeItem('h5_userInfo')
    localStorage.removeItem('h5_token')
    router.push('/login')
}
</script>

<style lang="less" scoped>
.container {
    background-color: #f0f0f0;
    height: 100vh;
    overflow: hidden;

    .user {
        width: 95%;
        height: 200px;
        background-color: #fff;
        text-align: center;
        border-radius: 10px;
        margin: 10px;

        .img {
            margin-top: 30px;
        }

        .text {
            line-height: 30px;
            font-weight: bold;
        }
    }

    .order {
        width: 90%;
        margin: 10px;
        border-radius: 5px;
        background-color: #fff;
        padding: 10px;

        .top {
            margin: 10px;
            line-height: 50px;
            display: flex;
            justify-content: space-between;

            .text1 {
                color: #333;
            }

            .text2 {
                color: #999;
            }

            border-bottom: 0.5px solid #f5f5f5;
        }

        .buttom {
            padding: 10px;
            display: flex;
            justify-content: space-around;

            .item {
                font-size: 14px;
                color: #999;
            }
        }
    }

    .foot {
        margin: 0 10px;
        padding: 10px;
        line-height: 50px;
        background-color: #fff;

        .foot1,
        .foot2 {
            display: flex;
            justify-content: space-between;
            color: #555;
        }

        .foot1 {
            border-bottom: 1px solid #f5f5f5;
        }
    }

    .quit {
        width: 90%;
        margin: 20px;
    }

    .quit_text {
        margin: 20px 0;
        text-align: center;
    }
}
</style>